//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;

using ProjectBase.Core;

namespace Survey.Entity
{
    /// <summary>
    /// Entity Question.
    /// </summary>
    [Serializable]
    public class Question : Persistent<int>
    {
        public virtual string Title { get; set; }

        public virtual string Description { get; set; }

        public virtual bool IsApproved { get; set; }

        public virtual DateTime ValidUntil { get; set; }

        private IList<Answer> _answers;

        public virtual IList<Answer> Answers
        {
            get { return _answers ?? (_answers = new List<Answer>()); }
            set { _answers = value; }
        }

        public virtual int TotalAnswersCount
        {
            get { return Answers.Sum(a => a.Count); }
        }

        #region override abstract

        /// <summary>
        /// Provides quick, string description about the 'Question' instance
        /// </summary>
        public override string ToDisplay()
        {
            // This method is often used on View
            // there for provide clear and understandable
            // set of properties (separated by spaces ' ')
            // which will quickly provide information about this instance
            return IDToDisplay + " " + Title;
        }

        /// <summary>
        /// Returned value should be handled as business unique key.
        /// Equal method (implemented in Tracked base class) will use it
        /// to compare two Questions
        /// </summary>
        protected override string GetDomainObjectSignature()
        {
            return "{0}|{1}".FormatWith(Title, ValidUntil.ToFileTimeUtc());
        }

        #endregion override abstract
    }
}